﻿@using KelonProud
@using KelonProud.Mvc.Models
@model  KelonProud.Mvc.Models.DropDownTableModel
@{
    var isReadOnly = Model.IsReadOnly ? "readonly" : "";
    var processDataFunName = Model.ProcessDataEvent.HasValue() ? Model.ProcessDataEvent : "onCommonProcessData";
    var enabledCss = Model.IsEnabled ? "" : "no-allowed";
}


<div class="input-group">
    <input type="hidden" class="form-control " id="@Model.Name" name="@Model.Name"  autocomplete="off" value="@Model.Value">
    <input type="text" class="form-control @enabledCss" id="txt_@Model.Name" name="txt_@Model.Name" @isReadOnly autocomplete="off">
    <div class="input-group-btn">
        <button type="button" class="btn btn-default dropdown-toggle @enabledCss" data-toggle="">
            <span class="caret"></span>
        </button>
        <ul class="dropdown-menu dropdown-menu-right" role="menu"></ul>
    </div>
</div>

<script>
    $("#txt_@Model.Name").bsSuggest({
        url: "@Model.Url",
        effectiveFields: @Html.Raw(Model.EffectiveFields),
        effectiveFieldsAlias: @Html.Raw(Model.EffectiveFieldsAlias),
        searchFields: ["Name"],
        //showHeader: false,
        autoSelect: true,
        defaultValue:"@Model.Value",
        showBtn: @Model.IsShowBtn.ToString().ToLower(),
        idField: "@Model.IdField",
        keyField: "@Model.KeyField",
        processData: function(json) {
           return @processDataFunName (json);
        }
    }).on('onSetSelectValue',
        function (e, keyword) {
            $("#@Model.Name").val(keyword["@Model.IdField"]);

            if ("@Model.CallbackEvent" !== "") {
                @Model.CallbackEvent (e,keyword);
            }
        });

    function doProcessDataEvent(json) {
        return json;
    }

    $(function() {
        if ("@Model.IsEnabled" === "False") {
            
        }
    });
</script>

